<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>点击显示和隐藏</title>
    <script src="../static/jquery-1.12.4.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .d {
            width: 80%;
            height: 400px;
            margin: 30px auto;
            border: 1px dotted pink;
        }
        .d2{
            width: 80px;
            height: 30px;
            background-color: chartreuse;
            display: block;
            z-index: 1;
        }
        .d3{
            width: 150px;
            height: 100px;
            background-color: aqua;
            display: block;
        }

    </style>
</head>
<body>
<div class="d">
    <div class="d1">点击显示，再次点击隐藏</div>
    <div class="d2" onclick="btn2()">点击</div>
    <div class="d3">显示&隐藏</div>
</div>
<script>
 function btn2(){
     var d3=document.getElementsByClassName("d3")[0];
      if(window.getComputedStyle(d3).display=='block') {//加载css后的display属性,未加载为空
         d3.style.display='none';
      }else{
          d3.style.display='block';
      }
   }
</script>
</body>
</html>